﻿package com.wongoing.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wongoing.base.BaseServiceImpl;
import com.wongoing.base.PageResult;
import com.wongoing.sys.dao.SysBasSiteDao;
import com.wongoing.sys.model.SysBasSite;
import com.wongoing.sys.service.SysBasSiteService;

@Service("passBasSiteService")
public class SysBasSiteServiceImpl extends BaseServiceImpl<SysBasSite> implements SysBasSiteService {
	private SysBasSiteDao dao;

	@Autowired
	public void setDao(SysBasSiteDao dao) {
		super.setDao(dao);
		this.dao = dao;
	}
	/**
	 * 功能说明：通过PageResult获取公司分页数据
	 * 修改说明：
	 * @author zhaoxihao
	 * @date 2017年10月17日 下午15:32:41
	 * @param pageResult 分页对象包含查询条件
	 * @return 返回分页对象包含页面数据
	 */
	public PageResult<SysBasSite> getSiteListPageResult(PageResult<SysBasSite> pageResult) {
		pageResult.getParam().put("offset", pageResult.getPageSize() * (pageResult.getPageCurrent() - 1));
		if (!"".equals(pageResult.getOrderField())) { pageResult.getParam().put("orderColumn", pageResult.getOrderField()); }
		pageResult.getParam().put("orderTurn", pageResult.getOrderDirection());
		List<SysBasSite> data = dao.getSiteListByParam(pageResult.getParam());
		pageResult.setList(data);
		int totalSize = dao.countOfSiteListByParam(pageResult.getParam());
		pageResult.setTotal(totalSize);
		return pageResult;
	}
	/**
	 * 
	 * 功能说明：储存上传图片地址
	 * 修改说明：
	 * @author zhaoxihao
	 * @date 2017-7-27 上午8:49:02
	 * @param id	主键id
	 * @param picture	图片地址
	 * @return
	 */
	
	public boolean setSitePicture(Integer id, String picture) {
		SysBasSite site = dao.getByPrimaryKey(id);
		site.setImgUrl(picture);
		int flag = dao.updateByPrimaryKey(site);
		switch (flag) {
		case 1:
			return true;
		case 0:
			return false;
		default:
			break;
		}
		return true;
	}
}
